<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>生态圈系统-登录</title>
  <link rel="icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">
  <link rel="shortcut icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">

  <!-- CSS  -->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link href="plugins/bootstrap-4.0.0/css/bootstrap.min.css" th:href="@{/plugins/bootstrap-4.0.0/css/bootstrap.min.css}" type="text/css" rel="stylesheet"/>
  <link href="css/materialize.css" th:href="@{/css/materialize.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="plugins/perfect-scrollbar/perfect-scrollbar.css" th:href="@{/plugins/perfect-scrollbar/perfect-scrollbar.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="plugins/bootstrap-datepicker/css/bootstrap-datepicker.css" th:href="@{/plugins/bootstrap-datepicker/css/bootstrap-datepicker.css}" type="text/css" rel="stylesheet"/>
  <link href="plugins/bootstrap-sweetalert/sweetalert.css" th:href="@{/plugins/bootstrap-sweetalert/sweetalert.css}" type="text/css" rel="stylesheet"/>
  <link href="css/style.css" th:href="@{/css/style.css}" type="text/css" rel="stylesheet"/>

  <style>

    .login-register {
      padding-top: 100px;
      height: 100%;
      position: relative;
    }

    .login-register:after {
      content: '';
	    display: block;
	    width: 100%;
	    height: 100%;
	    position: absolute;
	    top: 0;
	    right: 0;
	    bottom: 0;
	    left: 0;
      background-image:url(/kangchenjunga/images/back.jpg);
      background-repeat: no-repeat;
      background-size: cover;
      opacity: 0.3;
    }

    .card {
      width: 400px;
      margin: auto;
      text-align: center;
      position: absolute;
      top: 10rem;
      left: calc((100% - 400px) / 2);
    }

  </style>
</head>

<body>
  <section id="wrapper" style="height: 100%;">
    <div class="login-register" style="">

    </div>
    <div class="card" style="">
      <div class="card-body">
        <form th:action="@{/company/login}" method="post">
        <h5>欢迎使用生态圈系统企业端</h5>
        <p>V1.5.3</p>
				<div class="form-group">
				  <div class="col-xs-12 input-field">
				    <input class="form-control" type="text" name="companyId" required="" placeholder="企业ID">
				  </div>
				</div>
        <div class="form-group">
          <div class="col-xs-12 input-field">
            <input class="form-control" type="text" name="username" required="" placeholder="用户名">
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-12 input-field">
            <input class="form-control" type="password" name="password" required="" placeholder="密码">
          </div>
        </div>
        <div class="input-field" th:if="${param.error}">
          <span class="helper-text invalid left red-text">用户名或密码错误!</span>
        </div>
        <div class="form-group row right">
          <div class="col-md-12">
            <p>
            <label>
              <!-- <input type="checkbox" class="filled-in light-blue darken-1" checked="checked" />
              <span>记住密码</span> -->
            </label>
            </p>
          </div>
        </div>
        <div class="form-group text-center p-b-20">
          <div class="col-xs-12">
            <!-- <button id="login_btn" class="btn btn-block waves-effect waves-light light-blue darken-1" onclick="login()"> 登  录 </button> -->
            <button type="submit" class="btn btn-block waves-effect waves-light light-blue darken-1"> 登  录 </button>
          </div>
        </div>
        </form>
      </div>
    </div>
  </section>


  <!--  Scripts-->
  <!--  Scripts-->
  <script src="js/jquery-3.3.1.min.js" th:src="@{/js/jquery-3.3.1.min.js}"></script>
  <script src="js/materialize.js" th:src="@{/js/materialize.js}"></script>
  <script src="plugins/perfect-scrollbar/perfect-scrollbar.min.js" th:src="@{/plugins/perfect-scrollbar/perfect-scrollbar.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" th:src="@{/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" th:src="@{/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js}" charset="UTF-8"></script>
  <script src="plugins/bootstrap-sweetalert/sweetalert.min.js" th:src="@{/plugins/bootstrap-sweetalert/sweetalert.min.js}"></script>
  <script src="js/common.js" th:src="@{/js/common.js}"></script>
  <script>
    document.addEventListener('DOMContentLoaded', function () {

    });

    function login() {
    	$.ajax({
        url: "/kangchenjunga/api/v1/login",
        data: '{"username": "' + $('input[name="username"]').val() + '", "password": "' + $('input[name="password"]').val() + '", '
        	+ '"companyId": ' + $('input[name="companyId"]').val() + '}',
        contentType: "application/json;charset=utf-8",
        type: "POST",
        headers: {
          Accept: "application/json"
        },
        dataType: "text",
        success: function(data, textStatus) {
          console.log(data);
          if(data == 'success') {
        	document.cookie="opStore="+encodeURI($('input[name="opStore"]').val()) + '; path=/kangchenjunga/company/';
            swal("登录成功!", {
              icon: "success",
              //timer: 2000,
            });
            window.location.href = "/kangchenjunga/company/coupons/validate";
          } else {
        	document.cookie="opStore=; expire=0";
            swal("登录失败!", {
              icon: "error"
              //timer: 2000,
            });
          }

        }
      });

    }

    document.onkeydown = function(e){
      var theEvent = e || window.event;
      var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
      if (code == 13) {
        $('#login_btn').click();
      }
    }
  </script>

</body>

</html>
